package com.smartwebx.ha.web.admin.common.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import com.smartwebx.ha.dal.assign.bean.HaDirectory;
/**
 * 
 * 创建人：Dream~天涯 
 * 创建时间：2015-4-23 下午7:23:05
 * 邮箱：154494796@qq.com
 * 备注：
 */
public class HaTool {
	public static String getCookie(HttpServletRequest request, Cookie[] cookies, String name){
		    if (cookies == null || name == null || name.length() == 0) {
		      return null;
		    }
		    for (int i = 0; i < cookies.length; i++) {
		      if (name.equals(cookies[i].getName())) {
		        return cookies[i].getValue().toString();
		      }
		    }
		    return null;
	}
	
	public static Boolean getChecked(String string1, String string2){
		Boolean checked = false; 
		if(string1.indexOf("\""+string2+"\"")>=0){
			checked = true;
		}else{
			checked = false;
		}
		return checked;
	}

	public static String getValue(String driectorIds, List<HaDirectory> haDirectory) {
		if(haDirectory.size()==0){
			
		}else{
			driectorIds = haDirectory.get(0).getId().toString();
		}
		return driectorIds;
	}
	
	public static String string2Date(String time) { 
		Date d = new Date(time); 
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		time = formatter.format(d); 
		return time; 
	}
}
